<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>Recos配置详情</title>
        <meta name="description" content="Recos">
        <meta name="keywords" content="Recos">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <link rel="stylesheet" href="../plugins/elementui/index.css">
        <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
        <link rel="stylesheet" href="../css/sidebar.css">
        <link href="../plugins/quill/quill.snow.css" rel="stylesheet">
        <link href="../plugins/quill/quill.bubble.css" rel="stylesheet">
        <link href="../plugins/quill/quill.core.css" rel="stylesheet">
        <script src="../plugins/quill/quill.js"></script>
        <style>
            #textarea {
                background-color: #687084;
                color: rgba(255, 255, 255, 0.99);
            }
        </style>
    </head>
    <body class="hold-transition">

        <div id="app" class="app">
<!--            <iframe src="sidebar.html" ></iframe>-->
            <!-- 使用JavaScript加载侧边栏内容 -->
            <div id="sidebar-container"></div>

            <!-- 其他内容 -->
            <script>
                // 使用JavaScript加载侧边栏内容
                const sidebarContainer = document.getElementById("sidebar-container");
                const xhr = new XMLHttpRequest();
                xhr.open("GET", "sidebar.html", true);
                xhr.onreadystatechange = function () {
                    if (xhr.readyState === 4 && xhr.status === 200) {
                        sidebarContainer.innerHTML = xhr.responseText;
                    }
                };
                xhr.send();
            </script>
            <div id="page-container">

                <div class="content-header">
                    <h1 aria-label="center">Recos-配置详情</h1>
                    <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                        <el-breadcrumb-item :to="{ path: '/' }"></el-breadcrumb-item>
                    </el-breadcrumb>
                </div>

                <div class="app-container">
                    <div class="box">
                        <div><h3 style="color: rgb(104,112,132)" aria-label="center" > {{conf.appName}} : {{conf.serverport}}</h3></div>
                        <div><img src="../img/conficon.png" width="43" height="47">
                            <span style="font-size : large;color: rgb(104,112,132)" aria-label="center" > {{conf.coname}} </span></div>
                        <el-input
                                id="textarea"
                                type="textarea"
                                :rows="30"
                                placeholder="请输入内容"
                                v-model="conf.confContent">
                        </el-input>
                        <el-button slot="reference" type="info" size="mini" prop="href"
                                   @click="refreshConf">应用刷新配置</el-button>

                    </div>
                </div>
            </div>
        </div>
    </body>
    <!-- 引入组件库 -->
    <script src="../js/vue.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <script src="../plugins/elementui/index.js"></script>


    <script src="../plugins/quill/vue-quill-editor.js"></script>
    <script src="../js/token.js"></script>
    <script>

        var vue = new Vue({
            el: '#app',
            data:{
                textarea:'',
                conf:{
                    appName:'',
                    coname:'',
                    serverport:'',
                    confContent: '',
                },
                recosServerPath: "/recos/conf"
            },
            //钩子函数，VUE对象初始化完成后自动执行
            created() {
                if (!getToken() || getToken()==''){
                    window.location.href="./login.html"

                }
                this.initData();
            },
            methods: {
                initData(){
                    function getQueryString(name) {
                        let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
                        let r = window.location.search.substr(1).match(reg);
                        if (r != null) {
                            return decodeURIComponent(r[2]);
                        };
                        return null;
                    }
                    var appName=getQueryString("appName")
                    var token=getQueryString("token")
                    // setToken(token)
                    this.conf.appName=appName

                    axios.get(this.recosServerPath+"/getBindConf?appName="+appName,getAxiosConfig()).then((res)=>{
                        if (res.data.success){
                            this.conf.appName = res.data.data.appName;
                            this.conf.coname = res.data.data.coname;
                            this.conf.confContent = res.data.data.conf;
                            this.conf.serverport = res.data.data.serverport;
                            console.log(this.conf)
                        }else if (res.data.code==-555){
                            window.location.href="./login.html";
                        }
                    }).catch((error)=>{
                        if (error == "Error: Request failed with status code 403"){
                            this.$message.error("无操作权限");
                        }
                    });

                },
                refreshConf(){
                    axios.post(this.recosServerPath+"/refreshConf",this.conf,getAxiosConfig()).then((res)=>{
                        if (res.data.success){
                            alert(res.data.msg)
                        }else if (res.data.code==-555){
                            window.location.href="./login.html";
                        }
                    }).catch((error)=>{
                        if (error == "Error: Request failed with status code 403"){
                            this.$message.error("无操作权限");
                        }
                    });

                }

            }
        });
        Vue.use(window.VueQuillEditor);
    </script>
<style>
    .item {
        margin-top: 10px;
        margin-right: 40px;
    }
</style>
</html>